﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace Sample
{
  /// <summary>
  /// Interaction logic for Datagrid.xaml
  /// </summary>
  public partial class WinDatagrid : Window
  {
    public WinDatagrid()
    {
      InitializeComponent();

      //Facon List d'objet
      //List<myRowObj> listObj = new List<myRowObj>();

      //myRowObj robj1 = new myRowObj("One", 1);
      //listObj.Add(robj1);
      //myRowObj robj2 = new myRowObj("Two", 2);
      //listObj.Add(robj2);
      //myRowObj robj3 = new myRowObj("Tree", 3);
      //listObj.Add(robj3);

      //dgvSample2.ItemsSource = listObj;


      //Facon DataSet
      DataTable dt = new DataTable("MyTable");
      dt.Columns.Add("Name modif", typeof(string));
      dt.Columns.Add("Value modif", typeof(int));

      DataSet ds = new DataSet();
      ds.Tables.Add(dt);

      dt.Rows.Add("One", 1);
      dt.Rows.Add("Two", 2);
      dt.Rows.Add("Tree", 3);
      
      //Liaison au datacontext
      this.DataContext = ds.Tables[0].DefaultView;
      dgvSample2.ItemsSource = ds.Tables[0].DefaultView;
    }
  }

  public class myRowObj
  {
    private string m_Name;
    private int m_Value;

    public string Name
    {
      get { return m_Name; }
      set { m_Name = value; }
    }
    public int Value
    {
      get { return m_Value; }
      set { m_Value = value; }
    }

    public myRowObj (string _Name,int _Value)
	  {
      m_Name = _Name;
      m_Value = _Value;
	  }
  }
}
